<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-09-12 21:35:46
 * @LastEditTime: 2019-09-18 10:46:16
 * @LastEditors: Please set LastEditors
 -->
<template>
  <div class="mo-articlebox">
    <div v-if="loadingbox">
      <Loading></Loading>
    </div>
    <div v-if="!loadingbox" style="width:100%">
      <div v-for="v,i in articleList" class="articlebox-item" :id="v.id">
        <h2>
          <label>{{v.imoshi == '1'?'文':'连'}}</label>
          <span>{{v.ititle}}</span>
          <div class="articlebox-item-biaoqian">
            TA的标签:
            <span v-for="value,index in v.iclass.split(',')">{{v.iclass.split(',')[index]}}</span>
          </div>
        </h2>
        <!-- <div class="articlebox-item-owner">作者:{{v.artuser.user}}</div> -->

        <div class="articlebox-item-gaiyao">
          <img :src="v.artuser.avatar" />
          <p>简介:{{v.ijianjie}}</p>
        </div>
        <div class="articlebox-item-ctl">
          <div class="ctl-text">
            <div>
              <span @click="goRead(v.id)">查看原文</span>
              <div @click="loveArticle({articleId:v.id})" class="ctl-text-son">
                <Icon
                  type="md-heart-outline"
                  size="16"
                  v-if="!!!v.love"
                  style="cursor: pointer;margin-right:10px;"
                />
                <Icon
                  type="md-heart"
                  size="16"
                  color="red"
                  v-if="!!v.love"
                  style="cursor: pointer;margin-right:10px;"
                />
                <!-- <span>收藏文章</span> -->
              </div>
              <div class="updatedAt">活跃于：{{$moment(v.updatedAt).format("LLL")}}</div>
              <div class="ctl-text-son">
                <Icon type="md-eye" size="16" />
                <span>({{v.isee}})</span>
              </div>
            </div>
            <div>
              <span>
                <Icon type="md-sad" size="14" />举报
              </span>
            </div>
          </div>
        </div>
      </div>
      <Page
        :current="1"
        :total="articleListLen"
        :page-size="10"
        @on-change="changePage"
        simple
        v-if="!loading"
        class="page"
      />
    </div>
  </div>
</template>
<script>
import { Page } from "view-design";
import $ from "jquery";
import encrypt from "@/config/encrypt";
import moment from "moment";
import Loading from "@/examples/components/mo/anime/axiosLoading/axiosLoading3";
export default {
  name: "moArticleBox",
  data() {
    return {
      articleList: [],
      articleListLen: 0,
      loading: true,
      userId: localStorage.getItem("loginfo2"),
      loadingbox: true
    };
  },
  created() {
    this.getArticle();
  },
  mounted() {},
  methods: {
    //前往阅读
    goRead: function(e) {
      // let key = "1314";
      // let mid = encrypt.Encrypt(e.toString(), key);
      this.$axios
        .get(this.$store.getters.url + "/artisee?id=" + e)
        .then(res => {
          console.log(res.data);
        });
      this.$router.push("/read?artid=" + e);
    },
    changePage: function(e) {
      this.$axios
        .get(this.$store.getters.url + "/artlist", {
          params: {
            page: e - 1,
            userId: !!this.userId ? this.userId : "0"
          }
        })
        .then(res => {
          this.articleList = res.data.data;
        });
    },
    //收藏文章
    loveArticle: function(e) {
      this.$axios
        .get(this.$store.getters.url + "/artlove", {
          params: {
            userId: localStorage.getItem("loginfo2"),
            articleId: e.articleId
          }
        })
        .then(res => {
          this.$Message.success(res.data.msg);
          this.getArticle();
        });
    },
    //文章插寻
    getArticle: function(e) {
      this.$axios
        .get(this.$store.getters.url + "/artlist", {
          params: {
            page: 0,
            userId: !!this.userId ? this.userId : "0"
          }
        })
        .then(res => {
          console.log(res.data.data);
          this.articleList = res.data.data;
          this.$axios.get(this.$store.getters.url + "/artcount").then(res => {
            this.articleListLen = res.data.data;
            this.loading = false;
            this.loadingbox = false;
          });
        });
    }
  },
  components: { Page, Loading }
};
</script>
<style lang="scss" scoped>
.page {
  padding-bottom: 10px;
}
.mo-articlebox {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: auto;
  background-color: white;
  padding-top: 10px;
  .articlebox-item {
    position: relative;
    width: 100%;
    height: auto;
    box-sizing: border-box;
    border-bottom: 1px solid #ccc;
    // border-bottom: 1px solid #ddd;
    margin-bottom: 10px;
    padding-bottom: 10px;
    opacity: 0;
    h2 {
      display: flex;
      align-items: center;
      text-align: left;
      padding-left: 24px;
      height: 31px;
      span {
        width: auto;
        height: 25px;
      }
      label {
        display: inline-flex;
        width: 20px;
        height: 20px;
        background-color: black;
        color: white;
        font-size: 12px;
        border-radius: 4px;
        align-items: center;
        justify-content: center;
        margin-right: 10px;
      }
      .articlebox-item-biaoqian {
        display: inline-flex;
        align-items: center;
        width: auto;
        font-size: 12px;
        text-align: left;
        padding-left: 24px;
        color: black;
        height: 31px;
        span {
          height: 20px;
          display: inline-flex;
          align-items: center;
          font-size: 12px;
          box-sizing: border-box;
          border-radius: 12px;
          color: black;
          margin-left: 5px;
          padding-left: 6px;
          padding-right: 6px;
          border: 1px solid black;
          cursor: pointer;
          &:hover {
            color: white;
            background-color: black;
          }
        }
      }
    }
    .articlebox-item-gaiyao {
      display: flex;
      width: 100%;
      height: auto;
      font-size: 14px;
      text-align: left;
      padding-left: 24px;
      padding-right: 24px;
      // height: 44px;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      align-items: center;
      img {
        width: 35px;
        height: 35px;
        border-radius: 50%;
        margin-right: 10px;
      }
      p {
        display: flex;
        flex-wrap: wrap;
        width: auto;
        height: auto;
        white-space: pre-wrap;
      }
    }
    .articlebox-item-ctl {
      position: relative;
      display: flex;
      width: 100%;
      height: 25px;
      padding-left: 24px;
      padding-right: 24px;
      .ctl-text {
        display: flex;
        width: 100%;
        align-items: center;
        justify-content: space-between;
        div {
          display: flex;
          .updatedAt {
            text-align: left;
            color: rgba(0, 0, 0, 0.5);
            padding-right: 10px;
          }
          span {
            display: flex;
            align-items: center;
            margin-right: 10px;
            cursor: pointer;
          }
          .ctl-text-son {
            display: flex;
            align-items: center;
            span {
              display: flex;
              align-items: center;
            }
          }
          &:nth-last-child(1) {
            color: rgba(0, 0, 0, 0.6);
            &:hover {
              color: rgba(0, 0, 0, 1);
            }
          }
        }
      }
    }
  }
}
@mixin item($num) {
  $waitTime: ($num) * 0.2-0.2;
  animation: showArticle 0.2s ease-in-out #{$waitTime}s;
  animation-fill-mode: forwards;
}
@for $i from 1 through 10 {
  .articlebox-item:nth-child(#{$i}) {
    @include item($i);
  }
}
@keyframes showArticle {
  0% {
    opacity: 0;
    transform: translate3d(0px, 30px, 0px);
  }
  100% {
    opacity: 1;
    transform: translate3d(0px, 0px, 0px);
  }
}
</style>